#include "defines.h"
#include "IoOps.h"
#include "xmppFilter.h"
#include "xmppBot.h"
#include "callBackImpl.h"
#include <iostream>

/*
* Following class 'ht' exhibits usage of 'controlHeartbeat' message,
* and the methodology of implementation in user of C++ PA(Plugin Agent);
* Similar implementation could be seen in XrpXmpp...cpp class in code
* of XRP server; Though further details of parsing (textual message)
* might/shall change, but usage of 'controlHeartbeat()' interface
* will remain identical.
*
*/
class ht : public callBackImpl {
  public:
    ht(std::string msg):callBackImpl(msg), xb(NULL) {}
    xret
    handleMessage(const char *from,const char *msg,
                                char *wdata, size_t *len) {

      return callBackImpl::handleMessage( from, msg, wdata, len );
    }
    void
    bot( xmppBot * const _xb ) {
      this->xb = _xb;
    }
  private:
    xmppBot *xb;
};

int
main(int argc, char *argv[] )
{
  std::string stmsg = "Am Listening, send \"echo\" to me...";
  std::string ujid = "kamal@kamal.com/Office";
  std::string upasswd = "kamal";

  do {
    IoOps io = IoOps();
    ht cbi = ht(stmsg);
    xmppFilter xf = xmppFilter(&cbi);
    xmppBot xb = xmppBot( &io, &xf, false, NULL);
    xb.setJID(ujid, upasswd);
    cbi.bot( &xb );
    io.connect("192.168.1.2 ", 5222);
    xb.processXMPP( 121 );
    io.close();
    /*
      Under normal circumstances this shall never
      happen but world is not perfect hence if
      connection falls apart then re-try;
      wait for 10 secs and try again
    */
    ::sleep(10);
  } while(1);
  return 0;
}
/*
vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=2:encoding=utf-8:textwidth=80
*/
